package com.roast.util;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;

public class MyBeanFactory {

    private BeanFactory factory;

    public MyBeanFactory(String path) {
        try {
            FileSystemResource fsr = new FileSystemResource(path);
            this.factory = new XmlBeanFactory(fsr);
        } catch (BeanDefinitionStoreException e) {
            System.out.println("[MyBeanFactory:constructor:[" + e + "]]");
        }
    }

    public Object getBean(String beanID) {
        Object bean = null;
        try {
            if (factory != null) {
                bean = factory.getBean(beanID);
            }
        } catch (BeansException e) {
            System.out.println("[MyBeanFactory:getBean:[" + e + "]]");
        }
        return bean;
    }

}
